﻿var timerMaster = null;
var timer = null;
var delay = 5000;
var delayTimer = 1000;
var bInitiateSocket = false;

function checkTimer()
{
    timerID = window.setTimeout("getData()", delay);
}

function StartTheTimer()
{
    //timerMaster = window.setInterval("getData()", delay);
    timer = window.setInterval("getTime()", delayTimer);
}

function getData() {
    if (bInitiateSocket == false) {
        PageMethods.getData(true, onGetdataSuccess, onGetdataFail);
        bInitiateSocket = true;
    }
    else {
        PageMethods.getData(false, onGetdataSuccess, onGetdataFail);
    }
}

function onGetdataSuccess(response) {
    var divData = $get(g_str_divData);
    //var txtData = $get(g_str_txtData);
    
    var time = new Date();
    var curr_hour = time.getHours();
    var curr_min = time.getMinutes();
    var curr_sec = time.getSeconds();

    divData.innerHTML = response + ' ' + curr_hour + ":" + curr_min + ":" + curr_sec;

}

function onGetdataFail(error) {
    alert(error.get_message());
}

function getTime() {
    var spanTimer = $get(g_str_spanTimer);

    var time = new Date();
    var curr_hour = time.getHours();
    var curr_min = time.getMinutes();
    var curr_sec = time.getSeconds();

    spanTimer.innerHTML = curr_hour + ":" + curr_min + ":" + curr_sec;
}
